package com.ruoyi.forum.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.forum.dao.CircleLabelDao;
import com.ruoyi.forum.domain.CircleLabel;
import com.ruoyi.forum.model.LabelSort;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * service
 *
 * @author lxk
 * @date 2018-10-17 10:04:03
 */
@Service("circleLabelService")
public class CircleLabelService {

    @Autowired
    private CircleLabelDao circleLabelDao;


    @Transactional(rollbackFor = Exception.class)
    public void saveList(List<LabelSort> labelSorts) {
        for (LabelSort labelSort : labelSorts) {
            CircleLabel label = circleLabelDao.getById(labelSort.getId());
            label.setSortNum(labelSort.getSortNum());
            circleLabelDao.updateById(label);
        }
    }

    /**
     * 统计上线的板块
     *
     * @return
     */
    public long countBySid() {
        long count = circleLabelDao.countBySid();
        return count;
    }

    public CircleLabel selectById(String lableId) {
        return circleLabelDao.getById(lableId);
    }

    @Transactional(rollbackFor = Exception.class)
    public void save(CircleLabel circleLabel) {
        circleLabelDao.save(circleLabel);
    }

    public IPage<CircleLabel> page(Page<CircleLabel> pageInfo, LambdaQueryWrapper<CircleLabel> wrapper) {
        return circleLabelDao.page(pageInfo, wrapper);
    }

    @Transactional(rollbackFor = Exception.class)
    public void update(CircleLabel circleLabel) {
        circleLabelDao.updateById(circleLabel);
    }

    @Transactional(rollbackFor = Exception.class)
    public void delete(CircleLabel label) {
        circleLabelDao.removeById(label);
    }
}